package com.personal.book1.service;

import com.personal.book1.dao.BookDao;
import com.personal.book1.model.BookInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.List;

// 业务逻辑层
// 从Dao层拿取数据
@Service
public class BookService {
    @Autowired
    private BookDao bookDao;

    public List<BookInfo> getBookList() {
        // delete
        List<BookInfo> books = bookDao.mockBookData();
        // 2.处理数据 -> 将图书借阅状态由数字转换成文字
        for (BookInfo bookInfo : books) {
            if (bookInfo.getState() == 1) {
                bookInfo.setStateCN("可借阅");
            }else if (bookInfo.getState() == 2) {
                bookInfo.setStateCN("不可借阅");
            }
        }
        // 将处理好的数据返回给控制层 controller
        return books;
    }
}
